//运用Promise
const BASE = 'https://api2304.h5project.cn/1.1'
export const $http = function(url,method="GET",data={}){
  return new Promise((resolve,reject)=>{
    //axios内部使用的是XMLHttpRequest发起请求
    uni.request({
      url: BASE+url,
      method,
      data,
      header:{
        'X-LC-Id':'G6HU8PIbCl2Dm4DLVWt8mLmo-gzGzoHsz',
        'X-LC-Key':'lBuHPedslBnd7iHWxMW60rO0',
        'content-type':'application/json',
      },
      success:(res)=>{
        resolve(res)  //将成功的结构给到then
      },
      fail:(err)=>{
        reject(err) //将失败的信息给到catch
      }
    })
  })
}

export const $get = (url,data={})=>{
  return $http(url,'GET',data)
}